package com.reden;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Restrain extends Thread {
    private Automatic automatic;
    public Restrain(Automatic automatic) {
        this.automatic = automatic;
        start();
    }

    @Override
    public void run() {
        JFrame jFrame = new JFrame() {{
            setTitle("RedenClickTool");
            setSize(300, 200);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JRadioButton left = new JRadioButton("Left") {{
                setBounds(40, 20, 60, 20);
                setSelected(true);
            }};
            JRadioButton right = new JRadioButton("Right") {{
                setBounds(180, 20, 60, 20);
            }};
            ButtonGroup group = new ButtonGroup() {{
                add(left);
                add(right);
            }};
            JLabel label = new JLabel("Delay:") {{
                setBounds(20, 80, 80, 25);
            }};
            JTextField text = new JTextField(20) {{
                setBounds(100, 80, 165, 25);
                setText("10");
            }};
            JButton button = new JButton("Apply") {{
                setBounds(110, 120, 80, 30);
                addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        automatic.setLeft(left.isSelected());
                        automatic.setRight(right.isSelected());
                        automatic.setPeriod(Integer.valueOf(text.getText()));
                        automatic.setEnable(false);
                    }
                });
            }};

            Container con = getContentPane();
            con.setLayout(null);
            con.add(left);
            con.add(right);
            con.add(label);
            con.add(text);
            con.add(button);

            setVisible(true);
        }};
    }
}
